package com.tanhua.server.controller;


import com.tanhua.model.enums.CommentType;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.server.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessageController {

    @Autowired
    private MessageService messageService;



    /**
     * 根据环信ID查询用户详细信息
     * @param huanxinId
     * @return
     */
    @GetMapping("/userinfo")
    public ResponseEntity userInfo(String huanxinId){
        UserInfoVo vo = messageService.findHuanXinUserInfo(huanxinId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 添加联系人
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map){
        String userId = map.get("userId").toString();
        Long friendId = Long.valueOf(userId);
        messageService.addFriend(friendId);
        return ResponseEntity.ok(null);
    }

    /**
     * 联系人列表
     */
    @GetMapping("/contacts")
    public ResponseEntity contacts(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   String keyword){
          PageResult pr = messageService.friendList(page,pagesize,keyword);
          return ResponseEntity.ok(pr);
    }

    /**
     * 点赞列表
     */
    @GetMapping("/likes")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
       PageResult pr =  messageService.lists(page,pagesize, CommentType.LIKE.getType());
       return ResponseEntity.ok(pr);
    }

    /**
     * 喜欢列表
     */
    @GetMapping("/loves")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr =  messageService.lists(page,pagesize,CommentType.LOVE.getType());
        return ResponseEntity.ok(pr);
    }

    /**
     * 评论列表
     */
    @GetMapping("/comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr =  messageService.lists(page,pagesize,CommentType.COMMENT.getType());
        return ResponseEntity.ok(pr);
    }

    /**
     * 公告列表
     */
    @GetMapping("/announcements")
    public ResponseEntity announcements(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr =  messageService.announcements(page,pagesize);
        return ResponseEntity.ok(pr);
    }
}
